package com.hbnu.system.controller;


import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.dto.TPlatformDTO;
import com.hbnu.system.model.entity.TPlatform;
import com.hbnu.system.model.query.TPlatformPageQuery;
import com.hbnu.system.service.TPlatformService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * 平台信息表(TPlatform)表控制层
 *
 * @author makejava
 * @since 2025-07-16 14:25:37
 */
@RestController
@RequestMapping("tPlatform")
@Api(tags = "科研平台模块")
public class TPlatformController {
    /**
     * 服务对象
     */
    @Autowired
    private TPlatformService tPlatformService;

    @ApiOperation("科研平台-正式录入")
    @PostMapping("/addTPlatform")
    public Rest<Boolean> AddTPlatform(@RequestBody TPlatformDTO tPlatformdto){
        boolean add = tPlatformService.addnewtPlatform(tPlatformdto);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("科研平台-修改")
    @PostMapping("/updateTPlatform")
    public Rest<Boolean> updateTPlatform(@RequestBody TPlatformDTO tPlatformdto){
        boolean add = tPlatformService.updatetPlatform(tPlatformdto);
        return add ? Rest.success() : Rest.failed();
    }
    @ApiOperation("科研平台-名称查重")
    @GetMapping("/ChecktPlatformName")
    public Rest<Boolean> CheckTPlatformName(String name){
        boolean check = tPlatformService.checkTPlatformname(name);
        return check ? Rest.success() : Rest.failed();
    }


    @ApiOperation("科研平台-删除")
    @GetMapping("/DeleteTPlatform")
    public Rest<Boolean> DeleteTPlatform(String id) throws IOException {
        boolean delete = tPlatformService.deletetPlatform(id);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("科研平台-提交")
    @GetMapping("/ReCommitTPlatform")
    public Rest<Boolean> ReCommitTPlatform(String id){
        boolean add = tPlatformService.ReCommitTPlatform(id);
        return add ? Rest.success() : Rest.failed();
    }
    
    @ApiOperation("科研平台-撤回")
    @PostMapping("/WithdrawTPlatform")
    public Rest<String> WithdrawTPlatform(@RequestHeader("X-Token") String token, String id){
        Boolean b = tPlatformService.withdrawTPlatform(token, id);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("根据主键科研平台DTO查询")
    @GetMapping("/GetTPlatformById")
    public Rest<TPlatformDTO> GetPaperById(String id){
        TPlatformDTO tPlatformdto = tPlatformService.getTPlatformDTO(id);
        return Rest.success(tPlatformdto);
    }

    @ApiOperation("科研平台-院级通过")
    @GetMapping("/CollegeCheckPass")
    public Rest<String> CollegePasstPlatform(@RequestHeader("X-Token") String token,String id){
        Boolean b = tPlatformService.collegeCheckPass(token,id);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("科研平台-院级退回")
    @PostMapping("/CollegeCheckBack")
    public Rest<String> CollegeBacktPlatform(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = tPlatformService.collegeCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }


    @ApiOperation("科研平台-校级通过")
    @GetMapping("/SchoolCheckPass")
    public Rest<String> SchoolPasstPlatform(@RequestHeader("X-Token") String token,String id){
        Boolean b = tPlatformService.schoolCheckPass(token,id);
        return b ? Rest.success() : Rest.failed();
    }


    @ApiOperation("科研平台-校级退回")
    @PostMapping("/SchoolCheckBack")
    public Rest<String> SchoolBacktPlatform(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = tPlatformService.schoolCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("用户获取与自己相关的科研平台-分页")
    @PostMapping("/UserGetRelateTPlatform")
    public Rest<CommonPage<TPlatform>> UserGetRelateTPlatform(@RequestBody TPlatformPageQuery tPlatformPageQuery){
        CommonPage<TPlatform> tPlatformCommonPage =tPlatformService.userGetRelateTPlatformDTO(tPlatformPageQuery);
        return Rest.success(tPlatformCommonPage);
    }

    @ApiOperation("科研平台导出")
    @PostMapping("export")
    public Rest<CommonPage<TPlatform>> export(@RequestBody TPlatformPageQuery tPlatformPageQuery) {
        CommonPage<TPlatform> tPlatformCommonPage = tPlatformService.export(tPlatformPageQuery);
        return Rest.success(tPlatformCommonPage);
    }
    


}

